﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace Common
{
    public class DBThread
    {
        /// <summary>    
        /// 声明一个线程实例    
        /// </summary>   
        public  Thread mythread;
        public  Thread mythread_Insert;


        //开启线程
        public void Start() 
        {
            mythread = new Thread(new ThreadStart(work));
            mythread.Start();
        }

        //插入数据
        public void work()
        {
            Thread.Sleep(TimeSpan.FromMilliseconds(2000));
            while (true)
            {
                //string synchroDateStr = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");  
                Stopwatch sp = new Stopwatch();
                sp.Start();
                mythread_Insert = new Thread(new ThreadStart(dowork));
                mythread_Insert.Start();//方法放到后边,可以避免在系统启动的时候立即执行  
               
                Thread.Sleep(TimeSpan.FromMilliseconds(2000));
                sp.Stop();
                mythread_Insert.Abort();
                long xx = sp.ElapsedMilliseconds;
                Console.Write("定时器时间：" + xx.ToString() + "毫秒");
            }
        }



        public void dowork()
        {
            //Console.WriteLine("123");
            //string synchroDateStr = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 00:00:00");
            //int sleepMilliseconds = Convert.ToInt32(this.textBox3.Text);
            try
            {


                Stopwatch sp = new Stopwatch();
                sp.Start();
                for (int i = 0; i < 20; i++)
                {
                    //Mdl_Class.Operatechannel.AddTestData(dtpack);
                }
                sp.Stop();
                long xx = sp.ElapsedMilliseconds;
                Console.Write("插入数据的时间：" + xx.ToString() + "毫秒");

            }
            catch (Exception ex)
            {

                throw;
            }
        }  


        ////结束线程
        //public void Start()
        //{

        //}

        //发送包
        public void Add() 
        {

        }

        //删除包
        public void Delete() 
        {
            
        }
    }
}
